/*
 * Copyright (c) 2025 Li Auto Inc. and its affiliates
 * Licensed under the Apache License, Version 2.0(the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
*/
/*!*********************************************************************************************************************
 * @file        nvm_cfg.h
 * @brief       NvM 配置头文件
 * @details     主要包含 NvM 动态配置项
 * @date        {{get_generation_time()}}
 **********************************************************************************************************************/
#ifndef NVM_CFG_H
#define NVM_CFG_H

{% if check_nvm_notifybswm() == True %}
#include "BswM_NvM.h"
{%- endif %}

#ifdef __cplusplus
extern "C"
{
#endif

{%- set nvm_numofblocks = get_nvm_blocks() %}
{%- set crc32_inuse = check_crc32_inuse() %}
{%- set nvm_maxblocklength = get_nvm_maxblocklength() %}


#define NVM_DEV_ERROR_DETECT            ({{ gen_switch_macro(NvM_General["NvMCommon"], "NvMDevErrorDetect") }}) ///< NvM 使能/关闭错误检测
#define NVM_VERSION_INFO_API            ({{ gen_switch_macro(NvM_General["NvMCommon"], "NvMVersionInfoApi") }})     ///< NvM 使能/关闭版本信息API
#define NVM_SET_RAM_BLOCK_STATUS_API    ({{ gen_switch_macro(NvM_General["NvMCommon"], "NvMSetRamBlockStatusApi") }}) ///< NvM 使能/关闭设置RAM块状态API

#define NVM_API_CONFIG_CLASS            ({{ NvM_General["NvMCommon"]["NvMApiConfigClass"]["Value"] }})    ///< NvM API配置类别
#define NVM_COMPILED_CONFIG_ID          ({{ NvM_General["NvMCommon"]["NvMCompiledConfigId"]["Value"] }}u) ///< NvM 编译配置ID
#define NVM_CRC_NUM_OF_BYTES            ({{ get_int_value(NvM_General["NvMCommon"],"NvMCrcNumOfBytes") }}u) ///< NvM CRC校验字节数
#define NVM_CRC32_INUSE                 ({{ crc32_inuse }}) ///< NvM 中是否使用了 CRC32
#define NVM_DATASET_SELECTION_BITS      ({{ get_int_value(NvM_General["NvMCommon"],"NvMDatasetSelectionBits") }}u)  ///< NvM 数据集选择位
#define NVM_DRV_MODE_SWITCH             ({{ gen_switch_macro(NvM_General["NvMCommon"], "NvMDrvModeSwitch") }})  ///< NvM 使能/关闭驱动模式切换
#define NVM_DYNAMIC_CONFIGURATION       ({{ gen_switch_macro(NvM_General["NvMCommon"], "NvMDynamicConfiguration") }})  ///< NvM 使能/关闭动态配置
#define NVM_JOB_PRIORIZATION            ({{ gen_switch_macro(NvM_General["NvMCommon"], "NvMJobPrioritization") }})  ///< NvM 使能/关闭任务优先级
#define NVM_POLLING_MODE                ({{ gen_switch_macro(NvM_General["NvMCommon"], "NvMPollingMode") }})   ///< NvM 使能/关闭轮询模式
#define NVM_SIZE_IMMEDIATE_JOB_QUEUE    ({{ get_int_value(NvM_General["NvMCommon"],"NvMSizeImmediateJobQueue") }}u) ///< NvM 轮询模式下立即任务队列大小
#define NVM_SIZE_STANDARD_JOB_QUEUE     ({{ NvM_General["NvMCommon"]["NvMSizeStandardJobQueue"]["Value"] }}u)    ///< NvM 标准任务队列大小
#define NVM_BSWM_MULTIBLOCK_STATUSINFO  ({{ gen_switch_macro(NvM_General["NvMCommon"], "NvMBswMMultiBlockJobStatusInformation") }}) ///< NvM 使能/关闭通知BswM多块状态信息

#define NVM_NUM_OF_NVRAM_BLOCKS         ({{ nvm_numofblocks }}u)   ///< NvM 非易失性RAM块数量
#define NVM_MAX_BLOCK_LENGTH            ({{ nvm_maxblocklength }}u) ///< NvM 最大块长度


{%- if check_nvm_notifybswm() == True %}
#define NvM_INVOKE_CURRENT_MODE(id, res)    BswM_NvM_CurrentBlockMode((id),(res))    ///< 通知BswM当前块的模式变化
{%- else %}
#define NvM_INVOKE_CURRENT_MODE(id, res)      ///< 当不需要通知BswM时 定义为空宏
{%- endif %}

#define NvMConf_MultiBlockRequest (0u)
{%- for BlockDescriptor in NvM_Blocks.keys() %}
#define NvMConf_{{ BlockDescriptor }} ({{ loop.index }}u)   ///< 定义 {{ BlockDescriptor }} 的块ID
{%- endfor %}

#ifdef __cplusplus
}
#endif

#endif /*NVM_CFG_H*/

